package com.testitems.common.web.page;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.io.Serializable;
import java.util.List;

@Data
@ApiModel("分页参数")
public abstract class PageParam implements Serializable {

    @ApiModelProperty(value = "页码，默认为1", example = "1")
    private Integer current = 1;

    @ApiModelProperty(value = "页大小，默认为20", example = "20")
    private Integer size = 20;

    @ApiModelProperty("排序，column：数据库字段名称，asc：排序方式")
    private List<OrderItem> sorts;

    public void setCurrent(Integer current) {
        if (current == null || current <= 0) {
            this.current = 1;
        } else {
            this.current = current;
        }
    }

    public void setSize(Integer size) {
        if (size == null || size <= 0) {
            this.size = 20;
        } else {
            this.size = size;
        }
    }

    public void setSorts(List<OrderItem> sorts) {
        if (CollectionUtils.isEmpty(sorts)) {
            return;
        }
        this.sorts = sorts;
    }
}
